package com.afinal.intelligencetrash.Presenter;

import com.afinal.intelligencetrash.Model.bean.User;
import com.afinal.intelligencetrash.Model.db.LocalUserDB;
import com.afinal.intelligencetrash.Model.interfaces.RegisterModel;
import com.afinal.intelligencetrash.Model.interfaces.RequestHolder;
import com.afinal.intelligencetrash.Presenter.Interinfaces.ActionCallBack;
import com.afinal.intelligencetrash.Presenter.Interinfaces.RegisterService;
import com.afinal.intelligencetrash.ui.interfaces.RegisterView;

import javax.inject.Inject;

/**
 * Created by cyy on 17-10-11.
 */

public class RegisterServiceImp implements RegisterService {

    private RegisterModel model;
    private RegisterView view;
    @Override
    public void register(String username, String pwd1, final ActionCallBack callBack) {
        if(callBack != null){
            callBack.before();
        }
        model.register(username, pwd1, new RequestHolder<User>() {
            @Override
            protected void OnSuccess(User result) {
                view.showToast("注册成功");
            }

            @Override
            protected void OnFailure(int statusCode, String error) {
                view.showToast(error);
            }

            @Override
            protected void OnFinal(boolean isSuccess) {
                if(callBack != null){
                    callBack.after(isSuccess);
                }
            }
        });
    }

    @Inject
    public RegisterServiceImp(RegisterView view) {
        this.view = view;
        model = LocalUserDB.getInstance();
    }
}
